package com.tmt.im.wallet.controler;

import com.tmt.im.common.enums.ChannelType;
import com.tmt.im.wallet.controler.vo.WithdrawParamBindingRequest;
import com.tmt.im.wallet.controler.vo.WithdrawParamItem;
import com.tmt.im.wallet.helper.PrincipalHelper;
import com.tmt.im.wallet.service.WithdrawBindingParamService;
import com.tmt.springboot.common.restful.IExecuteResult;
import com.tmt.springboot.common.restful.ResultWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.scheduling.annotation.Async;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
 * 提现绑定参数控制器
 *
 * @Description TODO
 * @Author wuyi
 * @Date 2024/10/19 16:18
 * @Version 1.0
 **/
@Async("asyncTaskExecutor")
@Tag(name = "提现绑定参数相关接口", description = "提现绑定参数相关接口")
@RestController
@RequestMapping("${api-url-prefix}/withdraw")
public class WithdrawParamController {

    private final WithdrawBindingParamService bindingParamService;

    public WithdrawParamController(WithdrawBindingParamService bindingParamService) {
        this.bindingParamService = bindingParamService;
    }


    @Operation(summary = "绑定或更新提现参数接口",
            description = "绑定或更新提现参数接口",
            operationId = "bindingWithdrawParams",
            parameters = {
                    @Parameter(name = "request", description = "要绑定的提现参数")
            })
    @PostMapping(value = "/param/binding")
    public CompletableFuture<IExecuteResult<ResultWrapper<String>>> bindingWithdrawParams(WithdrawParamBindingRequest request,
                                                                                           Principal principal) {
        Long currentUserId = PrincipalHelper.getCurrentUserId(principal);
        IExecuteResult<String> result = bindingParamService.bindingWithdrawParams(currentUserId, request, principal);
        return CompletableFuture.completedFuture(ResultWrapper.from(result));
    }

    @Operation(summary = "删除提现参数接口",
            description = "删除提现参数接口",
            operationId = "deleteWithdrawParam",
            parameters = {
                    @Parameter(name = "channelType", description = "要删除的提现参数通道类型")
            })
    @PostMapping(value = "/param/delete")
    public CompletableFuture<IExecuteResult<ResultWrapper<Boolean>>> deleteWithdrawParam(@RequestParam("channelType") ChannelType channelType, Principal principal) {
        Long currentUserId = PrincipalHelper.getCurrentUserId(principal);
        IExecuteResult<Boolean> result = bindingParamService.deleteWithdrawParam(currentUserId, channelType, principal);
        return CompletableFuture.completedFuture(ResultWrapper.from(result));
    }

    @Operation(summary = "提现参数查询接口",
            description = "提现参数查询接口",
            operationId = "queryWithdrawParams")
    @GetMapping(value = "/param/query")
    public CompletableFuture<IExecuteResult<List<WithdrawParamItem>>> queryWithdrawParams(Principal principal) {
        Long currentUserId = PrincipalHelper.getCurrentUserId(principal);
        IExecuteResult<List<WithdrawParamItem>> result = bindingParamService.queryWithdrawParams(currentUserId, principal);
        return CompletableFuture.completedFuture(result);
    }

}
